<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('vue_admins')) {
            Schema::create('vue_admins', function (Blueprint $table) {
                $table->comment('管理员表');
                $table->increments('id')->comment('主键ID');
                $table->integer('created_id')->default(0)->comment('');
                $table->integer('created_at')->default(0)->comment('');
                $table->integer('updated_id')->default(0)->comment('');
                $table->integer('updated_at')->default(0)->comment('');
                $table->integer('deleted_id')->default(0)->nullable()->comment('');
                $table->integer('deleted_at')->default(0)->nullable()->comment('');
                $table->string('name', 60)->default('')->comment('用户名');
                $table->string('nickname', 60)->default('')->nullable()->comment('用户昵称');
                $table->string('password', 64)->default('')->comment('登录密码');
                $table->string('email', 60)->default('')->nullable()->comment('邮箱');
                $table->string('phone', 11)->default('')->nullable()->comment('手机号');
                $table->string('avatar', 200)->default('')->nullable()->comment('头像');
                $table->tinyInteger('sex')->default(0)->nullable()->comment('性别 0-保密 1-男 2-女');
                $table->tinyInteger('type')->default(1)->nullable()->comment('类型 0-超级管理员 1-其他');
                $table->string('lang', 10)->default('')->nullable()->comment('');
                $table->string('remark', 255)->default('')->nullable()->comment('');
                $table->integer('sorting')->default(0)->nullable()->comment('');
                $table->integer('auto_logout')->default(0)->nullable()->comment('');
                $table->integer('last_login_time')->default(0)->nullable()->comment('最后登录时间');
                $table->string('last_login_ip', 16)->default('')->nullable()->comment('最后登录ip');
                $table->string('token', 255)->default('')->nullable()->comment('身份令牌');
                $table->integer('token_expire')->default(0)->nullable()->comment('令牌有效期');
                $table->tinyInteger('status')->default(0)->comment('状态 0-未验证 1-正常 2-禁用');
            });
        }

        if (!Schema::hasTable('vue_admin_menu')) {
            Schema::create('vue_admin_menu', function (Blueprint $table) {
                $table->comment('后台菜单表');
                $table->increments('id')->comment('主键ID');
                $table->integer('created_id')->default(0)->comment('');
                $table->integer('created_at')->default(0)->comment('');
                $table->integer('updated_id')->default(0)->comment('');
                $table->integer('updated_at')->default(0)->comment('');
                $table->integer('deleted_id')->default(0)->nullable()->comment('');
                $table->integer('deleted_at')->default(0)->nullable()->comment('');
                $table->integer('parent_id')->default(0)->comment('上级ID');
                $table->string('name', 80)->default('')->comment('名称');
                $table->string('app', 15)->default('')->nullable()->comment('应用名');
                $table->string('controller', 30)->default('')->nullable()->comment('控制器名');
                $table->string('action', 100)->default('')->nullable()->comment('操作名');
                $table->string('route', 100)->default('')->nullable()->comment('路由');
                $table->string('icon', 60)->default('')->nullable()->comment('图标');
                $table->tinyInteger('type')->default(1)->nullable()->comment('类型 1=模块 2=列表 3=操作');
                $table->string('target', 20)->default('')->nullable()->comment('跳转方式');
                $table->string('remark', 255)->default('')->nullable()->comment('备注');
                $table->integer('sorting')->default(0)->nullable()->comment('');
                $table->tinyInteger('status')->default(0)->comment('状态 1-显示 2-不显示');
            });
        }

        if (!Schema::hasTable('vue_admin_roles')) {
            Schema::create('vue_admin_roles', function (Blueprint $table) {
                $table->comment('后台角色表');
                $table->increments('id')->comment('主键ID');
                $table->integer('created_id')->default(0)->comment('');
                $table->integer('created_at')->default(0)->comment('');
                $table->integer('updated_id')->default(0)->comment('');
                $table->integer('updated_at')->default(0)->comment('');
                $table->integer('deleted_id')->default(0)->nullable()->comment('');
                $table->integer('deleted_at')->default(0)->nullable()->comment('');
                $table->integer('parent_id')->default(0)->comment('上级ID');
                $table->string('name', 20)->default('')->comment('名称');
                $table->tinyInteger('role_type')->default(1)->nullable()->comment('类型 1-总后台 2-其他');
                $table->text('access')->nullable()->comment('用户组拥有的规则ID，多个规则用 , 隔开（rules）');
                $table->string('remark', 255)->default('')->nullable()->comment('');
                $table->integer('sorting')->default(0)->nullable()->comment('');
                $table->tinyInteger('status')->default(0)->comment('状态 1-正常 2-禁用');
            });
        }

        if (!Schema::hasTable('vue_admin_role_user')) {
            Schema::create('vue_admin_role_user', function (Blueprint $table) {
                $table->comment('管理员角色对应表');
                $table->increments('id')->comment('主键ID');
                $table->integer('role_id')->default(0)->comment('角色ID');
                $table->integer('admin_id')->default(0)->comment('管理员ID');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('vue_admins');
        Schema::dropIfExists('vue_admin_menu');
        Schema::dropIfExists('vue_admin_roles');
        Schema::dropIfExists('vue_admin_role_user');
    }
};
